Skip to content

feat(core)!: make Logger a Clone handle with const Logger::noop - #252

Open
tisonkun wants to merge 1 commit into
mainfrom
refactor/core-logger-handle
Open

tisonkun wants to merge 1 commit into
mainfrom
refactor/core-logger-handle

Conversation

@tisonkun

Copy link
Copy Markdown
Contributor

Summary

Make Logger a lightweight pointer-sized Clone handle over a shared immutable pipeline with a zero-allocation const fn Logger::noop(), and remove the redundant outer Arc<Logger> wrapper in LogBridge.

  • Pointer-sized Clone Logger handle and const fn Logger::noop() (logforth-core): Back Logger with Option<Arc<LoggerState>> (8B), implement Clone and Default, and normalize both Logger::noop() and empty LoggerBuilder::build() to None with zero heap allocations.
  • Direct Logger ownership in LogBridge (logforth-bridge-log, logforth): Store Logger directly inside LogBridge (#[derive(Clone)], pub const fn new(logger: Logger)) instead of Arc<Logger>, eliminating double reference-counting when retaining a Logger handle alongside global log installation.
  • Black-box Logger contract tests (logforth-core): Move Logger error-routing tests out of core/src/logger/log_impl.rs into core/tests/logger_test.rs and add coverage for pointer-size/trait bounds, noop / Default / empty builder behavior, and cross-thread shared Clone handles.

Breaking Changes

  • LogBridge::new in logforth-bridge-log now accepts Logger by value instead of impl Into<Arc<Logger>>; pass logger.clone() directly when retaining another handle.

`Logger` previously owned its `Vec<Dispatch>` and `Box<dyn ErrorSink>` directly without implementing `Clone` or `Default`, forcing callers and bridges such as `LogBridge` to wrap `Logger` in an external `Arc<Logger>` (or double-`Arc` `LogBridge` itself) whenever sharing a channel across threads or retaining a shutdown `flush()` handle, and preventing libraries from defaulting an optional logger to a `const` zero-allocation value.

Represent `Logger` in `logforth-core` as a pointer-sized `Option<Arc<LoggerState>>` (`Clone + Default`) with a zero-allocation `const fn Logger::noop()` (also returned when building an empty `LoggerBuilder`). Simplify `LogBridge` in `logforth-bridge-log` to store `Logger` directly (`Clone`, `const fn LogBridge::new(Logger)`) rather than `Arc<Logger>`, and move `Logger` behavioral tests into `core/tests/logger_test.rs`.

Signed-off-by: tison <wander4096@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant